﻿using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace syc.Sale
{
    public partial class 原料到货日报表 : System.Web.UI.Page
    {
        protected DateTime d1, d2, d3, d4, n;//d1月初日期，d2上旬截止日期,d3中旬截止日期,d4月末日期,n年初日期
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Button_Query_Click(null, null);      
                RiQi.Text = DateTime.Today.ToString("yyyy年M月d日");
            }
            GetData(DateTime.Parse(RiQi.Text).Year.ToString(), DateTime.Parse(RiQi.Text).Month.ToString());
            if (this.Message.Text == ".该扎帐月没有设置")
            {
                return;
            }
        }
        public void GetData(string yy, string mm)
        {
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            DataSet ds = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter("select 月初日期,上旬日期,中旬日期,月末日期,年初=(select 月初日期 from 供应处生产月设置 where 年度='" + yy + "' and 月份=1) from 供应处生产月设置 where 年度='" + yy + "' and 月份='" + mm + "'", Conn);
            sda.Fill(ds);
            try
            {
                d1 = DateTime.Parse(ds.Tables[0].Rows[0][0].ToString());
                d2 = DateTime.Parse(ds.Tables[0].Rows[0][1].ToString());
                d3 = DateTime.Parse(ds.Tables[0].Rows[0][2].ToString());
                d4 = DateTime.Parse(ds.Tables[0].Rows[0][3].ToString());
                n = DateTime.Parse(ds.Tables[0].Rows[0][4].ToString());
                this.Message.Text = ".查看成功";

            }
            catch
            {
                this.Message.Text = ".该扎帐月没有设置";
            }
        }
        protected void Button_Query_Click(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string part1 =
               @"<html xmlns:o='urn:schemas-microsoft-com:office:office'
xmlns:x='urn:schemas-microsoft-com:office:excel'
xmlns='http://www.w3.org/TR/REC-html40'>
<meta http-equiv=Content-Type content='text/html; charset=utf-8'>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>Chinese User</o:Author>
  <o:LastAuthor>Chinese User</o:LastAuthor>
  <o:LastPrinted>2011-03-14T04:06:54Z</o:LastPrinted>
  <o:Created>2010-05-26T08:35:24Z</o:Created>
  <o:LastSaved>2011-03-14T04:07:01Z</o:LastSaved>
  <o:Company>Chinese ORG</o:Company>
  <o:Version>11.9999</o:Version>
 </o:DocumentProperties>
</xml><![endif]-->
<style>
<!--td
	{height:25px;}
table
	{mso-displayed-decimal-separator:'\.';
	mso-displayed-thousand-separator:'\,';}
@page
	{margin:.79in .75in 1.0in .75in;
	mso-header-margin:.94in;
	mso-footer-margin:.5in;}
tr
	{mso-height-source:auto;
	mso-ruby-visibility:none;}
col
	{mso-width-source:auto;
	mso-ruby-visibility:none;}
br
	{mso-data-placement:same-cell;}
.style0
	{mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	white-space:nowrap;
	mso-rotate:0;
	mso-background-source:auto;
	mso-pattern:auto;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	border:none;
	mso-protection:locked visible;
	mso-style-name:常规;
	mso-style-id:0;}
td
	{mso-style-parent:style0;
	padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	border:none;
	mso-background-source:auto;
	mso-pattern:auto;
	mso-protection:locked visible;
	white-space:nowrap;
	mso-rotate:0;}
.xl24
	{mso-style-parent:style0;
	font-size:16.0pt;
	font-weight:700;}
.xl25
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:none;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl26
	{mso-style-parent:style0;
	font-size:16.0pt;
	font-weight:700;
	text-align:center;}
.xl27
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border-top:none;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl28
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:right;
	border-top:none;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl29
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	white-space:normal;}
.xl30
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;}
.xl31
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border:.5pt solid windowtext;}
.xl32
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border:.5pt solid windowtext;
	white-space:normal;}
.xl33
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;
	white-space:normal;}
.xl34
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl35
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl36
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:none;
	border-left:none;}
.xl37
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:none;
	border-left:none;}
.xl38
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border:.5pt solid windowtext;
	white-space:normal;}
.xl39
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border:.5pt solid windowtext;}
ruby
	{ruby-align:left;}
rt
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-char-type:none;
	display:none;}
-->
</style>
<!--[if gte mso 9]><xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>Sheet1</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:Print>
      <x:ValidPrinterInfo/>
      <x:PaperSizeIndex>9</x:PaperSizeIndex>
      <x:HorizontalResolution>600</x:HorizontalResolution>
      <x:VerticalResolution>600</x:VerticalResolution>
     </x:Print>
     <x:Selected/>
     <x:Panes>
      <x:Pane>
       <x:Number>3</x:Number>
       <x:ActiveRow>6</x:ActiveRow>
       <x:ActiveCol>9</x:ActiveCol>
      </x:Pane>
     </x:Panes>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet2</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet3</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:WindowHeight>7005</x:WindowHeight>
  <x:WindowWidth>10380</x:WindowWidth>
  <x:WindowTopX>720</x:WindowTopX>
  <x:WindowTopY>210</x:WindowTopY>
  <x:ProtectStructure>False</x:ProtectStructure>
  <x:ProtectWindows>False</x:ProtectWindows>
 </x:ExcelWorkbook>
</xml><![endif]-->
</head>

<body link=blue vlink=purple>

<table x:str border=0 cellpadding=0 cellspacing=0 width=767 style='border-collapse:
 collapse;table-layout:fixed;width:577pt'>
 <col width=37 style='mso-width-source:userset;mso-width-alt:1184;width:28pt'>
 <col width=30 style='mso-width-source:userset;mso-width-alt:960;width:23pt'>
 <col width=27 style='mso-width-source:userset;mso-width-alt:864;width:20pt'>
 <col width=56 style='mso-width-source:userset;mso-width-alt:1792;width:42pt'>
 <col width=61 style='mso-width-source:userset;mso-width-alt:1952;width:46pt'>
 <col width=56 style='mso-width-source:userset;mso-width-alt:1792;width:42pt'>
 <col width=61 style='mso-width-source:userset;mso-width-alt:1952;width:46pt'>
 <col width=64 style='mso-width-source:userset;mso-width-alt:2048;width:48pt'>
 <col width=63 style='mso-width-source:userset;mso-width-alt:2016;width:47pt'>
 <col width=70 style='mso-width-source:userset;mso-width-alt:2240;width:53pt'>
 <col width=62 style='mso-width-source:userset;mso-width-alt:1984;width:47pt'>
 <col width=61 style='mso-width-source:userset;mso-width-alt:1952;width:46pt'>
 <col width=119 style='mso-width-source:userset;mso-width-alt:3808;width:89pt'>
 <tr height=46 style='mso-height-source:userset;height:34.5pt'>
  <td colspan=12 height=46 class=xl26 width=648 style='height:34.5pt;
  width:488pt'>主 材 供 应 日 报</td>
  <td class=xl24 width=119 style='width:89pt'></td>
 </tr>
 <tr height=25 style='mso-height-source:userset;height:18.75pt'>
  <td colspan=3 height=25 class=xl27 style='height:18.75pt'>填报单位:供应处</td>
  <td class=xl25>　</td>
  <td colspan=8 class=xl28>填报日期:2011年3月14日</td>
  <td></td>
 </tr>
 <tr height=28 style='mso-height-source:userset;height:21.0pt'>
  <td rowspan=2 height=56 class=xl31 style='height:42.0pt;border-top:none'>品名</td>
  <td rowspan=2 class=xl32 width=30 style='border-top:none;width:23pt'>计量<br>
    单位</td>
  <td rowspan=2 class=xl31 style='border-top:none'>序号</td>
  <td rowspan=2 class=xl31 style='border-top:none'>供货单位</td>
  <td colspan=2 class=xl31 style='border-left:none'>当日到货量</td>
  <td colspan=2 class=xl31 style='border-left:none'>当月到货量</td>
  <td colspan=2 class=xl31 style='border-left:none'>全年累计到货量</td>
  <td colspan=2 class=xl31 style='border-left:none'>年合同量</td>
  <td></td>
 </tr>
 <tr height=28 style='mso-height-source:userset;height:21.0pt'>
  <td height=28 class=xl31 style='height:21.0pt;border-top:none;border-left:
  none'>J55</td>
  <td class=xl31 style='border-top:none;border-left:none'>N80</td>
  <td class=xl31 style='border-top:none;border-left:none'>J55</td>
  <td class=xl31 style='border-top:none;border-left:none'>N80</td>
  <td class=xl31 style='border-top:none;border-left:none'>J55</td>
  <td class=xl31 style='border-top:none;border-left:none'>N80</td>
  <td class=xl31 style='border-top:none;border-left:none'>J55</td>
  <td class=xl31 style='border-top:none;border-left:none'>N80</td>
  <td></td>
 </tr>";
            string part3 = @"
 <tr height=28 style='mso-height-source:userset;height:21.0pt'>
  <td colspan=4 height=28 class=xl36 style='height:21.0pt'>供应负责人:<span
  style='mso-spacerun:yes'>  </span>赵宏斌</td>
  <td colspan=6 style='mso-ignore:colspan'></td>
  <td colspan=2 class=xl36>填报人:张芳</td>
  <td></td>
 </tr>
 <![if supportMisalignedColumns]>
 <tr height=0 style='display:none'>
  <td width=37 style='width:28pt'></td>
  <td width=30 style='width:23pt'></td>
  <td width=27 style='width:20pt'></td>
  <td width=56 style='width:42pt'></td>
  <td width=61 style='width:46pt'></td>
  <td width=56 style='width:42pt'></td>
  <td width=61 style='width:46pt'></td>
  <td width=64 style='width:48pt'></td>
  <td width=63 style='width:47pt'></td>
  <td width=70 style='width:53pt'></td>
  <td width=62 style='width:47pt'></td>
  <td width=61 style='width:46pt'></td>
  <td width=119 style='width:89pt'></td>
 </tr>
 <![endif]>
</table>";
            Response.Charset = "utf-8";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.ContentType = "application/ms-excel";
            Response.AddHeader("content-disposition", "attachment; filename=\"" + Server.UrlEncode("主材供应日报表") + ".xls\"");
            Response.Write(part1.Replace("@填报日期", this.RiQi.Text));
//          SqlConnection Conn = new SqlConnection();
//            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
//            Conn.Open();
//            SqlCommand Cmd = new SqlCommand();
//            Cmd.Connection = Conn;
//            string sql = @"
//            declare @年度 int
//            declare @月份 int
//            declare @月初日期  date
//            declare @年初日期  date             
//            select @年度=年度,@月份=月份,@月初日期=月初日期 from 供应处生产月设置 where 月初日期<='*日期' and 月末日期>='*日期' 
//            select @年初日期=月初日期 from 供应处生产月设置 where 年度=@年度 and 月份=1                                                            
//            select distinct 主材名称,名称,isnull(dbo.当月累计(主材ID,名称,'*日期','*日期'),0) as 当日到货量,isnull(dbo.当月累计(主材ID,名称,'*日期',@月初日期),0) as 当月累计量
//            ,isnull(dbo.当月累计(主材ID,名称,'*日期',@年初日期),0) as 当年累计量,[dbo].[当年合同量](主材ID,名称,@年度) as 全年合同量,[dbo].[当月合同量](主材ID,名称,@年度,@月份) as 当月合同量
//            ,主材ID
//           from 主要原材料到货日记录 where 主材名称 is not null order by 主材名称 desc";
//            DateTime 日期 = DateTime.Parse(this.RiQi.Text);
//            sql = sql.Replace("*日期",日期.ToShortDateString());
//            Cmd.CommandText = sql;
//            DataSet ds = new DataSet();
//            SqlDataAdapter sda = new SqlDataAdapter(sql, Conn);
//            sda.Fill(ds);
//            DataTable dt = ds.Tables[0];
//            int 油管光管 = dt.Select("主材ID=1").Length;
//            int 套管光管 = dt.Select("主材ID=2").Length;
//            int 油管接箍光管 = dt.Select("主材ID=3").Length;
//            int 套管接箍光管 = dt.Select("主材ID=4").Length;
//            int 成品套管接箍 = dt.Select("主材ID=6").Length;
//            SqlDataReader Reader = Cmd.ExecuteReader();
//            int i = 0;
//            int j = 0;
//            int k = 0;
//            int l = 0;
//            int m = 0;
//            double 合计1 = 0;
//            double 合计2 = 0;
//            double 合计3 = 0;
//            double 合计4 = 0;
//            double 合计5 = 0;
//            while (Reader.Read())
//            {
//                string str = Reader.GetString(0);

//                if (Reader.GetString(0) == "油管光管" && Reader.GetInt32(7) == 1)
//                {
                    
//                    if (i == 0)
//                    {
//                        Response.Write("<tr height=28 style='mso-height-source:userset;height:21.0pt'><td rowspan=" + 油管光管 + "  class=xl35 style='border-bottom:.5pt solid black;height:" + 21 * 油管光管 + "pt;border-top:none'>" + Reader.GetString(0) + "</td>");
//                    }
//                    i++;
//                    Response.Write(" <td class=xl43>" + i + "</td>");
//                    Response.Write(" <td class=xl43>" + Reader.GetString(1) + "</td>");
//                    if (Reader.IsDBNull(2))
//                    {
//                        Response.Write(" <td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(2) + "</td>");
//                    }
//                    if (Reader.IsDBNull(3))
//                    {
//                        Response.Write(" <td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(3) + "</td>");
//                    }

//                    if (Reader.IsDBNull(4))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(4) + "</td>");
//                    }
//                    if (Reader.IsDBNull(5))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(5) + "</td>");
//                    }
//                    if (Reader.IsDBNull(6))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(6) + "</td>");
//                    }
//                    合计1 = 合计1 + Reader.GetDouble(2);
//                    合计2 = 合计2 + Reader.GetDouble(3);
//                    合计3 = 合计3 + Reader.GetDouble(4);
//                    合计4 = 合计4 + Reader.GetDouble(5);
//                    合计5 = 合计5 + Reader.GetDouble(6);
//                    Response.Write("<td></td></tr>");
//                    if (i == 油管光管)
//                    {
//                        Response.Write("<tr height=28 style='mso-height-source:userset;height:14.25pt'><td height=25  class=xl35 style='height:18.0pt'>合计</td>");
//                        Response.Write("<td class=xl43>　</td>");
//                        Response.Write("<td class=xl43>　</td>");
//                        Response.Write("<td class=xl43>" + 合计1 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计2 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计3 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计4 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计5 + "</td>");                       
//                        Response.Write("<td>　</td></tr>");
//                         合计1 = 0;
//                         合计2 = 0;
//                         合计3 = 0;
//                         合计4 = 0;
//                         合计5 = 0;
//                    }
                    
//                }
//                if (Reader.GetString(0) == "套管光管" && Reader.GetInt32(7) == 2)
//                {
//                    if (j == 0)
//                    {
//                        Response.Write(" <tr height=28 style='mso-height-source:userset;height:21.0pt'><td rowspan=" + 套管光管 + " height=38 class=xl35 style='border-bottom:.5pt solid black;height:" + 21 * 套管光管 + "pt;border-top:none'>" + Reader.GetString(0) + "</td>");
//                    }
//                    j++;
//                    Response.Write(" <td class=xl43>" + j + "</td>");
//                    Response.Write(" <td class=xl43>" + Reader.GetString(1) + "</td>");
//                    if (Reader.IsDBNull(2))
//                    {
//                        Response.Write(" <td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(2) + "</td>");
//                    }
//                    if (Reader.IsDBNull(3))
//                    {
//                        Response.Write(" <td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(3) + "</td>");
//                    }

//                    if (Reader.IsDBNull(4))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(4) + "</td>");
//                    }
//                    if (Reader.IsDBNull(5))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(5) + "</td>");
//                    }
//                    if (Reader.IsDBNull(6))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(6) + "</td>");
//                    }
//                    Response.Write("<td></td></tr>");
//                    合计1 = 合计1 + Reader.GetDouble(2);
//                    合计2 = 合计2 + Reader.GetDouble(3);
//                    合计3 = 合计3 + Reader.GetDouble(4);
//                    合计4 = 合计4 + Reader.GetDouble(5);
//                    合计5 = 合计5 + Reader.GetDouble(6);
//                    if (j == 套管光管)
//                    {
//                        Response.Write("<tr height=28 style='mso-height-source:userset;height:14.25pt'><td height=25 class=xl35 style='height:18.0pt'>合计</td>");
//                        Response.Write("<td class=xl43>　</td>");
//                        Response.Write("<td class=xl43>　</td>");
//                        Response.Write("<td class=xl43>" + 合计1 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计2 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计3 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计4 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计5 + "</td>");
//                        Response.Write("<td>　</td></tr>");
//                        合计1 = 0;
//                        合计2 = 0;
//                        合计3 = 0;
//                        合计4 = 0;
//                        合计5 = 0;
//                    }
//                }
//                if (Reader.GetString(0) == "油管接箍光管" && Reader.GetInt32(7) == 3)
//                {
//                    if (k == 0)
//                    {
//                        Response.Write(" <tr height=28 style='mso-height-source:userset;height:21.0pt'><td rowspan=" + 油管接箍光管 + " height=38 class=xl35 style='border-bottom:.5pt solid black;height:" + 21 * 油管接箍光管 + "pt;border-top:none'>" + Reader.GetString(0) + "</td>");
//                    }
//                    k++;
//                    Response.Write(" <td class=xl43>" + k + "</td>");
//                    Response.Write(" <td class=xl43>" + Reader.GetString(1) + "</td>");
//                    if (Reader.IsDBNull(2))
//                    {
//                        Response.Write(" <td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(2) + "</td>");
//                    }
//                    if (Reader.IsDBNull(3))
//                    {
//                        Response.Write(" <td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(3) + "</td>");
//                    }

//                    if (Reader.IsDBNull(4))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(4) + "</td>");
//                    }
//                    if (Reader.IsDBNull(5))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(5) + "</td>");
//                    }
//                    if (Reader.IsDBNull(6))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(6) + "</td>");
//                    }
//                    Response.Write("<td></td></tr>");
//                    合计1 = 合计1 + Reader.GetDouble(2);
//                    合计2 = 合计2 + Reader.GetDouble(3);
//                    合计3 = 合计3 + Reader.GetDouble(4);
//                    合计4 = 合计4 + Reader.GetDouble(5);
//                    合计5 = 合计5 + Reader.GetDouble(6);
//                    if (k == 油管接箍光管)
//                    {
//                        Response.Write("<tr height=28 style='mso-height-source:userset;height:14.25pt'><td height=25 class=xl35 style='height:18.0pt'>合计</td>");
//                        Response.Write("<td class=xl43>　</td>");
//                        Response.Write("<td class=xl43>　</td>");
//                        Response.Write("<td class=xl43>" + 合计1 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计2 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计3 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计4 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计5 + "</td>");
//                        Response.Write("<td>　</td></tr>");
//                        合计1 = 0;
//                        合计2 = 0;
//                        合计3 = 0;
//                        合计4 = 0;
//                        合计5 = 0;
//                    }
//                }
//                if (Reader.GetString(0) == "套管接箍光管" && Reader.GetInt32(7) == 4)
//                {
//                    if (l == 0)
//                    {
//                        Response.Write(" <tr height=28 style='mso-height-source:userset;height:21.0pt'><td rowspan=" + 套管接箍光管 + " height=38 class=xl35 style='border-bottom:.5pt solid black;height:" + 21 * 套管接箍光管 + "pt;border-top:none'>" + Reader.GetString(0) + "</td>");
//                    }
//                    l++;
//                    Response.Write(" <td class=xl43>" + l + "</td>");
//                    Response.Write(" <td class=xl43>" + Reader.GetString(1) + "</td>");
//                    if (Reader.IsDBNull(2))
//                    {
//                        Response.Write(" <td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(2) + "</td>");
//                    }
//                    if (Reader.IsDBNull(3))
//                    {
//                        Response.Write(" <td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(3) + "</td>");
//                    }

//                    if (Reader.IsDBNull(4))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(4) + "</td>");
//                    }
//                    if (Reader.IsDBNull(5))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(5) + "</td>");
//                    }
//                    if (Reader.IsDBNull(6))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(6) + "</td>");
//                    }
//                    Response.Write("<td></td></tr>");
//                    合计1 = 合计1 + Reader.GetDouble(2);
//                    合计2 = 合计2 + Reader.GetDouble(3);
//                    合计3 = 合计3 + Reader.GetDouble(4);
//                    合计4 = 合计4 + Reader.GetDouble(5);
//                    合计5 = 合计5 + Reader.GetDouble(6);
//                    if (l == 套管接箍光管)
//                    {
//                        Response.Write("<tr height=28 style='mso-height-source:userset;height:14.25pt'><td height=25 class=xl35 style='height:18.0pt'>合计</td>");
//                        Response.Write("<td class=xl43>　</td>");
//                        Response.Write("<td class=xl43>　</td>");
//                        Response.Write("<td class=xl43>" + 合计1 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计2 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计3 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计4 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计5 + "</td>");
//                        Response.Write("<td>　</td></tr>");
//                        合计1 = 0;
//                        合计2 = 0;
//                        合计3 = 0;
//                        合计4 = 0;
//                        合计5 = 0;
//                    }
//                }
//                if (Reader.GetString(0) == "成品套管接箍" && Reader.GetInt32(7) == 6)
//                {
//                    if (m == 0)
//                    {
//                        Response.Write(" <tr height=28 style='mso-height-source:userset;height:21.0pt'><td rowspan=" + 成品套管接箍 + " height=38 class=xl35 style='border-bottom:.5pt solid black;height:" + 21 * 成品套管接箍 + "pt;border-top:none'>" + Reader.GetString(0) + "</td>");
//                    }
//                    m++;
//                    Response.Write(" <td class=xl43>" + m + "</td>");
//                    Response.Write(" <td class=xl43>" + Reader.GetString(1) + "</td>");
//                    if (Reader.IsDBNull(2))
//                    {
//                        Response.Write(" <td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(2) + "</td>");
//                    }
//                    if (Reader.IsDBNull(3))
//                    {
//                        Response.Write(" <td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(3) + "</td>");
//                    }

//                    if (Reader.IsDBNull(4))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(4) + "</td>");
//                    }
//                    if (Reader.IsDBNull(5))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(5) + "</td>");
//                    }
//                    if (Reader.IsDBNull(6))
//                    {
//                        Response.Write("<td class=xl43></td>");
//                    }
//                    else
//                    {
//                        Response.Write(" <td class=xl43>" + Reader.GetDouble(6) + "</td>");
//                    }
//                    Response.Write("<td></td></tr>");
//                    合计1 = 合计1 + Reader.GetDouble(2);
//                    合计2 = 合计2 + Reader.GetDouble(3);
//                    合计3 = 合计3 + Reader.GetDouble(4);
//                    合计4 = 合计4 + Reader.GetDouble(5);
//                    合计5 = 合计5 + Reader.GetDouble(6);
//                    if (m == 成品套管接箍)
//                    {
//                        Response.Write("<tr height=28 style='mso-height-source:userset;height:14.25pt'><td height=25 class=xl35 style='height:18.0pt'>合计</td>");
//                        Response.Write("<td class=xl43>　</td>");
//                        Response.Write("<td class=xl43>　</td>");
//                        Response.Write("<td class=xl43>" + 合计1 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计2 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计3 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计4 + "</td>");
//                        Response.Write("<td class=xl43>" + 合计5 + "</td>");
//                        Response.Write("<td>　</td></tr>");
//                        合计1 = 0;
//                        合计2 = 0;
//                        合计3 = 0;
//                        合计4 = 0;
//                        合计5 = 0;
//                    }                  
//                }   

//            }
                    SqlConnection Conn = new SqlConnection();
                    Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
                    Conn.Open();
                    SqlCommand Cmd = new SqlCommand();
                    Cmd.Connection = Conn;
                    string sql = @"
            declare @年度 int
            declare @月份 int
            declare @月初日期  date
            declare @年初日期  date             
            select @年度=年度,@月份=月份,@月初日期=月初日期 from 供应处生产月设置 where 月初日期<='*日期' and 月末日期>='*日期' 
            select @年初日期=月初日期 from 供应处生产月设置 where 年度=@年度 and 月份=1                                                            
            select distinct 原料供货单位.ID,名称,
            isnull(dbo.当月累计(2,名称,'*日期','*日期'),0) as 当日到货量J55
            , isnull(dbo.当月累计(102,名称,'*日期','*日期'),0) as 当日到货量N80
            ,isnull(dbo.当月累计(2,名称,'*日期',@月初日期),0)  as 当月到货量,isnull(dbo.当月累计(102,名称,'*日期',@月初日期),0)  as 当月到货量N80
            ,isnull(dbo.当月累计(2,名称,'*日期',@年初日期),0) as 当年累计量j55,isnull(dbo.当月累计(102,名称,'*日期',@年初日期),0) as 当年累计量N80 
            ,[dbo].[当年合同量](2,名称,@年度) as 全年合同量j55,[dbo].[当年合同量](102,名称,@年度) as 全年合同量N80
            from 采购原料合同 inner join 原料供货单位 on 原料供货单位.ID=采购原料合同.供货ID  where 年度=@年度 and 采购原料合同.原料ID=2 or 采购原料合同.原料ID=102";
                    DateTime 日期 = DateTime.Parse(this.RiQi.Text);
                    sql = sql.Replace("*日期", 日期.ToShortDateString());
                    Cmd.CommandText = sql;
                    DataSet ds = new DataSet();
                    SqlDataAdapter sda = new SqlDataAdapter(sql, Conn);
                    sda.Fill(ds);
                    DataTable dt = ds.Tables[0];
                    int 套管光管 = dt.Rows.Count;
                    SqlDataReader Reader = Cmd.ExecuteReader();                 
                    int i =0;
                    double 套管J55当日 = 0;
                    double 套管N80当日 = 0;
                    double 套管J55当月 = 0;
                    double 套管N80当月 = 0;
                    double 套管J55全年 = 0;
                    double 套管N80全年 = 0;

                    int 套管J55全年合同量 = 0;
                    int 套管N80全年合同量 = 0;
                    
                    if (套管光管 != 0)
                    {
                        while (Reader.Read())
                        {

                            if (i == 0)
                            {
                                Response.Write("<tr style='mso-height-source:userset;height:21.0pt'><td rowspan=" + (套管光管 + 1) + " height=52 class=xl38 width=37 style='height:60.0pt;border-top:none;width:28pt'>套管<br>光管</td>");
                                Response.Write("<td rowspan=" + (套管光管 + 1) + " class=xl35>T</td>");
                                Response.Write("<td class=xl35 style='height:21.0pt'>" + (i + 1) + "</td>");
                            }
                            else
                            {
                                Response.Write("<tr height=28 style='mso-height-source:userset;height:21.0pt'><td height=28 class=xl35 style='height:21.0pt'>" + (i + 1) + "</td>");
                            }
                            Response.Write("<td class=xl35>" + Reader.GetString(1) + "</td>");
                            Response.Write("<td class=xl35>" + Reader.GetDouble(2) + "</td>");
                            Response.Write("<td class=xl35>" + Reader.GetDouble(3) + "</td>");
                            Response.Write("<td class=xl35>" + Reader.GetDouble(4) + "</td>");
                            Response.Write("<td class=xl35>" + Reader.GetDouble(5) + "</td>");
                            Response.Write("<td class=xl35>" + Reader.GetDouble(6) + "</td>");
                            Response.Write("<td class=xl35>" + Reader.GetDouble(7) + "</td>");
                            Response.Write("<td class=xl35>" + Reader.GetDouble(8) + "</td>");
                            Response.Write("<td class=xl35>" + Reader.GetDouble(9) + "</td>");
                            Response.Write("</tr>");
                            套管J55当日 += Reader.GetDouble(2);
                            套管N80当日 += Reader.GetDouble(3);
                            套管J55当月 += Reader.GetDouble(4);
                            套管N80当月 += Reader.GetDouble(5);
                            套管J55全年 += Reader.GetDouble(6);
                            套管N80全年 += Reader.GetDouble(7);

                            套管J55全年合同量 = int.Parse(Reader.GetDouble(8).ToString());
                            套管N80全年合同量 = int.Parse(Reader.GetDouble(9).ToString());
                            i++;
                        }
                        Response.Write(" <tr height=24 style='mso-height-source:userset;height:18.0pt'><td colspan=2 height=24 class=xl35 style='height:18.0pt;border-left:none'>合计</td>");
                        Response.Write("<td class=xl35 >" + 套管J55当日.ToString("0.000") + "</td>");
                        Response.Write("<td class=xl35>" + 套管N80当日.ToString("0.000") + "</td>");
                        Response.Write("<td class=xl35>" + 套管J55当月.ToString("0.000") + "</td>");
                        Response.Write("<td class=xl35>" + 套管N80当月.ToString("0.000") + "</td>");
                        Response.Write("<td class=xl35>" + 套管J55全年.ToString("0.000") + "</td>");
                        Response.Write("<td class=xl35>" + 套管N80全年.ToString("0.000") + "</td>");
                        Response.Write("<td class=xl35>" + 套管J55全年合同量 + "</td>");
                        Response.Write("<td class=xl35>" + 套管N80全年合同量 + "</td>");
                        Response.Write("</tr>");
                    }
                     Reader.Close();
                     string sql1 = @"
            declare @年度 int
            declare @月份 int
            declare @月初日期  date
            declare @年初日期  date             
            select @年度=年度,@月份=月份,@月初日期=月初日期 from 供应处生产月设置 where 月初日期<='*日期' and 月末日期>='*日期' 
            select @年初日期=月初日期 from 供应处生产月设置 where 年度=@年度 and 月份=1                                                            
            select distinct 原料供货单位.ID,名称,
            isnull(dbo.当月累计(1,名称,'*日期','*日期'),0) as 当日到货量J55
            , isnull(dbo.当月累计(101,名称,'*日期','*日期'),0) as 当日到货量N80
            ,isnull(dbo.当月累计(1,名称,'*日期',@月初日期),0)  as 当月到货量,isnull(dbo.当月累计(101,名称,'*日期',@月初日期),0)  as 当月到货量N80
            ,isnull(dbo.当月累计(1,名称,'*日期',@年初日期),0) as 当年累计量j55,isnull(dbo.当月累计(101,名称,'*日期',@年初日期),0) as 当年累计量N80 
            ,[dbo].[当年合同量](1,名称,@年度) as 全年合同量j55,[dbo].[当年合同量](101,名称,@年度) as 全年合同量N80
           from 采购原料合同 inner join 原料供货单位 on 原料供货单位.ID=采购原料合同.供货ID  where 年度=@年度 and 采购原料合同.原料ID=1 or 采购原料合同.原料ID=101";
                     sql1 = sql1.Replace("*日期", 日期.ToShortDateString());
                     Cmd.CommandText = sql1;
                     DataSet ds1 = new DataSet();
                     SqlDataAdapter sda1 = new SqlDataAdapter(sql1, Conn);
                     sda1.Fill(ds1);
                     DataTable dt1 = ds1.Tables[0];
                     int 油管光管 = dt1.Rows.Count;                    
                     double 油管J55当日 = 0;
                     double 油管N80当日 = 0;
                     double 油管J55当月 = 0;
                     double 油管N80当月 = 0;
                     double 油管J55全年 = 0;
                     double 油管N80全年 = 0;

                     int 油管J55全年合同量 = 0;
                     int 油管N80全年合同量 = 0;
                     Reader = Cmd.ExecuteReader();
                     int j = 0;
                    
                     if (油管光管 != 0)
                     {
                         while (Reader.Read())
                         {

                             if (j == 0)
                             {
                                 Response.Write("<tr style='mso-height-source:userset;height:21.0pt'><td rowspan=" + (油管光管 + 1) + " height=52 class=xl38 width=37 style='height:60.0pt;border-top:none;width:28pt'>油管<br>光管</td>");
                                 Response.Write("<td rowspan=" + (油管光管 + 1) + " class=xl35>T</td>");
                                 Response.Write("<td class=xl35 style='height:21.0pt'>" + (j + 1) + "</td>");
                             }
                             else
                             {
                                 Response.Write("<tr height=28 style='mso-height-source:userset;height:21.0pt'><td height=28 class=xl35 style='height:21.0pt'>" + (j + 1) + "</td>");
                             }
                             Response.Write("<td class=xl35>" + Reader.GetString(1) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(2) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(3) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(4) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(5) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(6) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(7) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(8) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(9) + "</td>");
                             Response.Write("</tr>");
                             油管J55当日 += Reader.GetDouble(2);
                             油管N80当日 += Reader.GetDouble(3);
                             油管J55当月 += Reader.GetDouble(4);
                             油管N80当月 += Reader.GetDouble(5);
                             油管J55全年 += Reader.GetDouble(6);
                             油管N80全年 += Reader.GetDouble(7);

                             油管J55全年合同量 = int.Parse(Reader.GetDouble(8).ToString());
                             油管N80全年合同量 = int.Parse(Reader.GetDouble(9).ToString());
                             j++;
                         }
                         Response.Write(" <tr height=24 style='mso-height-source:userset;height:18.0pt'><td colspan=2 height=24 class=xl35 style='height:18.0pt;border-left:none'>合计</td>");
                         Response.Write("<td class=xl35 >" + 油管J55当日.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 油管N80当日.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 油管J55当月.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 油管N80当月.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 油管J55全年.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 油管N80全年.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 油管J55全年合同量 + "</td>");
                         Response.Write("<td class=xl35>" + 油管N80全年合同量 + "</td>");
                         Response.Write("</tr>");
                     }
                     Reader.Close();
                     string sql2 = @"
            declare @年度 int
            declare @月份 int
            declare @月初日期  date
            declare @年初日期  date             
            select @年度=年度,@月份=月份,@月初日期=月初日期 from 供应处生产月设置 where 月初日期<='*日期' and 月末日期>='*日期' 
            select @年初日期=月初日期 from 供应处生产月设置 where 年度=@年度 and 月份=1                                                            
            select distinct 原料供货单位.ID,名称,
            isnull(dbo.当月累计(4,名称,'*日期','*日期'),0) as 当日到货量J55
            ,isnull(dbo.当月累计(104,名称,'*日期','*日期'),0) as 当日到货量N80 
            ,isnull(dbo.当月累计(4,名称,'*日期',@月初日期),0)  as 当月到货量,isnull(dbo.当月累计(104,名称,'*日期',@月初日期),0)  as 当月到货量N80
            ,isnull(dbo.当月累计(4,名称,'*日期',@年初日期),0) as 当年累计量j55,isnull(dbo.当月累计(104,名称,'*日期',@年初日期),0) as 当年累计量N80 
            ,[dbo].[当年合同量](4,名称,@年度) as 全年合同量j55,[dbo].[当年合同量](104,名称,@年度) as 全年合同量N80 
            from 采购原料合同 inner join 原料供货单位 on 原料供货单位.ID=采购原料合同.供货ID  where 年度=@年度 and 采购原料合同.原料ID=4 or 采购原料合同.原料ID=104";
                     sql2 = sql2.Replace("*日期", 日期.ToShortDateString());
                     Cmd.CommandText = sql2;
                     DataSet ds2 = new DataSet();
                     SqlDataAdapter sda2 = new SqlDataAdapter(sql2, Conn);
                     sda2.Fill(ds2);
                     DataTable dt2 = ds2.Tables[0];
                     int 套管接箍光管 = dt2.Rows.Count;
                     double 套管接箍J55当日 = 0;
                     double 套管接箍N80当日 = 0;
                     double 套管接箍J55当月 = 0;
                     double 套管接箍N80当月 = 0;
                     double 套管接箍J55全年 = 0;
                     double 套管接箍N80全年 = 0;

                     int 套管接箍J55全年合同量 = 0;
                     int 套管接箍N80全年合同量 = 0;
                     Reader = Cmd.ExecuteReader();
                     int k= 0;
                   
                     if (套管接箍光管 != 0)
                     {
                         while (Reader.Read())
                         {

                             if (k == 0)
                             {
                                 Response.Write("<tr style='mso-height-source:userset;height:21.0pt'><td rowspan=" + (套管接箍光管 + 1) + " height=52 class=xl38 width=37 style='height:60.0pt;border-top:none;width:28pt'>套管<br>接箍<br>光管</td>");
                                 Response.Write("<td rowspan=" + (套管接箍光管 + 1) + " class=xl35>T</td>");
                                 Response.Write("<td class=xl35 style='height:21.0pt'>" + (k + 1) + "</td>");
                             }
                             else
                             {
                                 Response.Write("<tr height=28 style='mso-height-source:userset;height:21.0pt'><td height=28 class=xl35 style='height:21.0pt'>" + (k + 1) + "</td>");
                             }
                             Response.Write("<td class=xl35>" + Reader.GetString(1) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(2) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(3) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(4) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(5) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(6) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(7) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(8) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(9) + "</td>");
                             Response.Write("</tr>");
                             套管接箍J55当日 += Reader.GetDouble(2);
                             套管接箍N80当日 += Reader.GetDouble(3);
                             套管接箍J55当月 += Reader.GetDouble(4);
                             套管接箍N80当月 += Reader.GetDouble(5);
                             套管接箍J55全年 += Reader.GetDouble(6);
                             套管接箍N80全年 += Reader.GetDouble(7);

                             套管接箍J55全年合同量 += int.Parse(Reader.GetDouble(8).ToString());
                             套管接箍N80全年合同量 += int.Parse(Reader.GetDouble(9).ToString());
                             k++;
                         }
                         Response.Write(" <tr height=24 style='mso-height-source:userset;height:18.0pt'><td colspan=2 height=24 class=xl35 style='height:18.0pt;border-left:none'>合计</td>");
                         Response.Write("<td class=xl35 >" + 套管接箍J55当日.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 套管接箍N80当日.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 套管接箍J55当月.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 套管接箍N80当月.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 套管接箍J55全年.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 套管接箍N80全年.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 套管接箍J55全年合同量 + "</td>");
                         Response.Write("<td class=xl35>" + 套管接箍N80全年合同量 + "</td>");
                         Response.Write("</tr>");
                     }
                     Reader.Close();
                     string sql3 = @"
            declare @年度 int
            declare @月份 int
            declare @月初日期  date
            declare @年初日期  date             
            select @年度=年度,@月份=月份,@月初日期=月初日期 from 供应处生产月设置 where 月初日期<='*日期' and 月末日期>='*日期' 
            select @年初日期=月初日期 from 供应处生产月设置 where 年度=@年度 and 月份=1                                                            
             select distinct 原料供货单位.ID,名称,
            isnull(dbo.当月累计(3,名称,'*日期','*日期'),0) as 当日到货量J55
           ,isnull(dbo.当月累计(103,名称,'*日期','*日期'),0) as 当日到货量N80 
            ,isnull(dbo.当月累计(3,名称,'*日期',@月初日期),0)  as 当月到货量,isnull(dbo.当月累计(103,名称,'*日期',@月初日期),0)  as 当月到货量N80
            ,isnull(dbo.当月累计(3,名称,'*日期',@年初日期),0) as 当年累计量j55,isnull(dbo.当月累计(103,名称,'*日期',@年初日期),0) as 当年累计量N80 
            ,[dbo].[当年合同量](3,名称,@年度) as 全年合同量j55,[dbo].[当年合同量](103,名称,@年度) as 全年合同量N80 
           from 采购原料合同 inner join 原料供货单位 on 原料供货单位.ID=采购原料合同.供货ID  where 年度=@年度 and 采购原料合同.原料ID=3 or 采购原料合同.原料ID=103";
                     sql3 = sql3.Replace("*日期", 日期.ToShortDateString());
                     Cmd.CommandText = sql3;
                     DataSet ds3 = new DataSet();
                     SqlDataAdapter sda3 = new SqlDataAdapter(sql3, Conn);
                     sda3.Fill(ds3);
                     DataTable dt3 = ds3.Tables[0];
                     int 油管接箍光管 = dt3.Rows.Count;
                     double 油管接箍J55当日 = 0;
                     double 油管接箍N80当日 = 0;
                     double 油管接箍J55当月 = 0;
                     double 油管接箍N80当月 = 0;
                     double 油管接箍J55全年 = 0;
                     double 油管接箍N80全年 = 0;

                     int 油管接箍J55全年合同量 = 0;
                     int 油管接箍N80全年合同量 = 0;
                     Reader = Cmd.ExecuteReader();
                     int l = 0;
                 
                     if (油管接箍光管 != 0)
                     {
                         while (Reader.Read())
                         {

                             if (l == 0)
                             {
                                 Response.Write("<tr style='mso-height-source:userset;height:21.0pt'><td rowspan=" + (油管接箍光管 + 1) + " height=52 class=xl38 width=37 style='height:60.0pt;border-top:none;width:28pt'>油管<br>接箍<br>光管</td>");
                                 Response.Write("<td rowspan=" + (油管接箍光管 + 1) + " class=xl35>T</td>");
                                 Response.Write("<td class=xl35 style='height:21.0pt'>" + (l + 1) + "</td>");
                             }
                             else
                             {
                                 Response.Write("<tr height=28 style='mso-height-source:userset;height:21.0pt'><td height=28 class=xl35 style='height:21.0pt'>" + (l + 1) + "</td>");
                             }
                             Response.Write("<td class=xl35>" + Reader.GetString(1) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(2) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(3) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(4) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(5) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(6) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(7) + "</td>");
                             Response.Write("<td class=xl35>" + int.Parse(Reader.GetDouble(8).ToString()) + "</td>");
                             Response.Write("<td class=xl35>" + int.Parse(Reader.GetDouble(9).ToString()) + "</td>");
                             Response.Write("</tr>");
                             油管接箍J55当日 += Reader.GetDouble(2);
                             油管接箍N80当日 += Reader.GetDouble(3);
                             油管接箍J55当月 += Reader.GetDouble(4);
                             油管接箍N80当月 += Reader.GetDouble(5);
                             油管接箍J55全年 += Reader.GetDouble(6);
                             油管接箍N80全年 += Reader.GetDouble(7);

                             油管接箍J55全年合同量 += int.Parse(Reader.GetDouble(8).ToString());
                             油管接箍N80全年合同量 += int.Parse(Reader.GetDouble(9).ToString());
                             l++;
                         }
                         Response.Write(" <tr height=24 style='mso-height-source:userset;height:18.0pt'><td colspan=2 height=24 class=xl35 style='height:18.0pt;border-left:none'>合计</td>");
                         Response.Write("<td class=xl35 >" + 油管接箍J55当日.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 油管接箍N80当日.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 油管接箍J55当月.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 油管接箍N80当月.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 油管接箍J55全年.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 油管接箍N80全年.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 油管接箍J55全年合同量 + "</td>");
                         Response.Write("<td class=xl35>" + 油管接箍N80全年合同量 + "</td>");
                         Response.Write("</tr>");
                     }
                     Reader.Close();
                     string sql4 = @"
            declare @年度 int
            declare @月份 int
            declare @月初日期  date
            declare @年初日期  date             
            select @年度=年度,@月份=月份,@月初日期=月初日期 from 供应处生产月设置 where 月初日期<='*日期' and 月末日期>='*日期' 
            select @年初日期=月初日期 from 供应处生产月设置 where 年度=@年度 and 月份=1                                                            
             select distinct 原料供货单位.ID,名称,
            isnull(dbo.当月累计(6,名称,'*日期','*日期'),0) as 当日到货量J55
            ,isnull(dbo.当月累计(106,名称,'*日期','*日期'),0) as 当日到货量N80 
            ,isnull(dbo.当月累计(6,名称,'*日期',@月初日期),0)  as 当月到货量,isnull(dbo.当月累计(106,名称,'*日期',@月初日期),0)  as 当月到货量N80
            ,isnull(dbo.当月累计(6,名称,'*日期',@年初日期),0) as 当年累计量j55,isnull(dbo.当月累计(106,名称,'*日期',@年初日期),0) as 当年累计量N80 
            ,[dbo].[当年合同量](6,名称,@年度) as 全年合同量j55,[dbo].[当年合同量](106,名称,@年度) as 全年合同量N80 
            from 采购原料合同 inner join 原料供货单位 on 原料供货单位.ID=采购原料合同.供货ID  where 年度=@年度 and 采购原料合同.原料ID=6 or 采购原料合同.原料ID=106";
                     sql4 = sql4.Replace("*日期", 日期.ToShortDateString());
                     Cmd.CommandText = sql4;
                     DataSet ds4 = new DataSet();
                     SqlDataAdapter sda4 = new SqlDataAdapter(sql4, Conn);
                     sda4.Fill(ds4);
                     DataTable dt4 = ds4.Tables[0];
                     int 成品套管接箍 = dt4.Rows.Count;
                     double 成品套管接箍J55当日 = 0;
                     double 成品套管接箍N80当日 = 0;
                     double 成品套管接箍J55当月 = 0;
                     double 成品套管接箍N80当月 = 0;
                     double 成品套管接箍J55全年 = 0;
                     double 成品套管接箍N80全年 = 0;

                     int 成品套管接箍J55全年合同量 = 0;
                     int 成品套管接箍N80全年合同量 = 0;
                     Reader = Cmd.ExecuteReader();
                     int m = 0;
                   
                     if (成品套管接箍 != 0)
                     {
                         while (Reader.Read())
                         {

                             if (m == 0)
                             {
                                 Response.Write("<tr style='mso-height-source:userset;height:21.0pt'><td rowspan=" + (成品套管接箍 + 1) + " height=52 class=xl38 width=37 style='height:60.0pt;border-top:none;width:28pt'>套管<br>成品<br>接箍</td>");
                                 Response.Write("<td rowspan=" + (成品套管接箍 + 1) + " class=xl35>支</td>");
                                 Response.Write("<td class=xl35 style='height:21.0pt'>" + (m + 1) + "</td>");
                             }
                             else
                             {
                                 Response.Write("<tr height=28 style='mso-height-source:userset;height:21.0pt'><td height=28 class=xl35 style='height:21.0pt'>" + (m + 1) + "</td>");
                             }
                             Response.Write("<td class=xl35>" + Reader.GetString(1) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(2) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(3) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(4) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(5) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(6) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(7) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(8) + "</td>");
                             Response.Write("<td class=xl35>" + Reader.GetDouble(9) + "</td>");
                             Response.Write("</tr>");
                             成品套管接箍J55当日 += Reader.GetDouble(2);
                             成品套管接箍N80当日 += Reader.GetDouble(3);
                             成品套管接箍J55当月 += Reader.GetDouble(4);
                             成品套管接箍N80当月 += Reader.GetDouble(5);
                             成品套管接箍J55全年 += Reader.GetDouble(6);
                             成品套管接箍N80全年 += Reader.GetDouble(7);

                             成品套管接箍J55全年合同量 += int.Parse(Reader.GetDouble(8).ToString());
                             成品套管接箍N80全年合同量 += int.Parse(Reader.GetDouble(9).ToString());
                             m++;
                         }
                         Response.Write(" <tr height=24 style='mso-height-source:userset;height:18.0pt'><td colspan=2 height=24 class=xl35 style='height:18.0pt;border-left:none'>合计</td>");
                         Response.Write("<td class=xl35 >" + 成品套管接箍J55当日.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 成品套管接箍N80当日.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 成品套管接箍J55当月.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 成品套管接箍N80当月.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 成品套管接箍J55全年.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 成品套管接箍N80全年.ToString("0.000") + "</td>");
                         Response.Write("<td class=xl35>" + 成品套管接箍J55全年合同量 + "</td>");
                         Response.Write("<td class=xl35>" + 成品套管接箍N80全年合同量 + "</td>");
                         Response.Write("</tr>");
                     }
                     Reader.Close();
                    
                    Conn.Close();
            Response.Write(part3);
            Response.End();
        }
    }
}
